<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

<title>xx文档列表</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<link rel="stylesheet" href="css/luyan/luyan.css" type="text/css"></link>
 <link rel="stylesheet" href="easyui/themes/icon.css" type="text/css"></link>
	 <link rel="stylesheet" href="easyui/themes/default/easyui.css" type="text/css"></link>
	 <script type="text/javascript" src="easyui/jquery-1.8.3.js"></script>
	 <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
<script type="text/javascript">
	$(function(){
			$("#div2").dialog({closed:true});
			$("#div3").dialog({closed:true});
			$("#div4").dialog({closed:true});
	  		$("#dg").datagrid({
	  			url:"files/findAll.do",
	  			striped:true,	  			
	  			rownumbers:true,
	  			title:'"'+$("#foldername").val()+'"'+"文档列表",
	  			pagination:true,
	  			pageList:[10,20,50],
	  			columns:[[{
	  				title:"名称",
	  				field:"name",
	  				width:160,
	  				align:"right",
	  				
	  			},{
	  				title:"类型",
	  				field:"文件夹",
	  				width:180,
	  				align:"center",
	  				formatter:function(){
	  					return "文件";
	  				}
	  			},{
	  				title:"所有者",
	  				field:"userid",
	  				width:100,
	  				align:"right"
	  			},{
	  				title:"创建时间",
	  				field:"createdate",
	  				width:170,
	  				align:"right",
	  				formatter:date
	  			},{
	  				title:"操作",
	  				field:"id",
	  				width:152,
	  				align:"right",
	  				formatter:function (value,row,index){
						return "<a  href='files/download.do?id="+row.id+"'>下载</a>&nbsp;&nbsp;&nbsp;<a onclick='update("+row.id+")' href='javascript:void(0)'>修改</a>&nbsp;&nbsp;&nbsp;<a onclick='del("+row.id+")' href='javascript:void(0)'>删除</a>";
						}	  				
	  			}]],
	  			toolbar:[{text:"新增文件",iconCls:"icon-add",handler:function(){
	  				add();
	  			}}]   	
	  		});
	  	//点击按钮动态查询
	  	$("#btn").click(function(){
	  		var name = $("#name2").val();
	  		var folderid = $("#folderid").val();
	  		
	  		var data = "name="+name+
	  		"&folderid="+folderid;
	  		$("#dg").datagrid({
	  			url:"files/findByParam.do?"+data
	  		});
	  	
	  	});
	  	
	  	$("#div3").dialog({
		    title: "修改文件",
		    width: 400,
		    height: 350,
		    closed: true,
		    buttons:[{
				text:"修改",
				handler:function(){
					var data ="id="+$("#id1").val()+
					"&name="+$("#name1").val()+
	  				"&userid="+$("#userid1").html()+
	  				"&createdate="+$("#createdate1").html()+
	  				"&folderid="+$("#folderid").val();
					$.get("files/update.do",data,function(data){
								alert(data);
								$("#div3").dialog("close");
								$("#dg").datagrid("reload");
							},"text");  	
				}
			},{
				text:"取消",
				handler:function(){
					$("#div3").dialog("close");
				}
			}]
		});		
	  });
		function date(value){
			return value.year+1900+"-"
			+(value.month+1)+"-"+value.date;
		}
		function update(value){
			
			$("#div3").dialog("open");	
			$.post("files/findByid.do","id="+value,function(data){
  				$("#id1").val(value);
  				$("#name1").val(data.name);
  				$("#path1").html(data.path);
  				var re= date(data.createdate);
  				$("#createdate1").html(re);
  				$("#userid1").html(data.userid);
  			},"json");
		};
		function del(value){
			$.messager.confirm("提示框", "你确定要删除吗?",function(r){
				if(r){
					var data = "id="+value;
					$.post(
		  				"files/updateStatus.do",
		  				data,
		  				function(data){
		  				alert(data);
		  				$("#dg").datagrid("reload");
		  				
		  				},
		  				"text"
		  			);
				}
			});
		};
		
		function add(){
		$("#sp").html(date1());
		$("#div4").dialog({
  			title:"添加文件",
  			width:400,
  			heigeht:200,
  			closed:false,
  			modal:true,
  			buttons:[{text:"保存",
  					handler:function(){
  						var data = "userid="+$("#userid4").val()+
  						"&createdate="+$("#sp").html()+
  						"&name="+$("#name4").val()+
  						"&folderid="+$("#folderid").val();
  						
  							$.post(
  								"files/add.do",
  								data,
  								function(data){
  								alert(data);
  									$("#div4").dialog("close");
  								$("#dg").datagrid("reload");
  								},
  								"text"
  							);
  					}
  					},
  					]
  		});
		}
		function date1(){
		var date1 = new Date();
		var tt = ""+date1.getFullYear()+"-";
		tt+=(date1.getMonth()+1)+"-";
		tt+=date1.getDate()+" ";
		tt+=date1.getHours()+":";
		tt+=date1.getMinutes()+":";
		tt+=date1.getSeconds();
		return tt;
		}
		
		
		function down(value){
		var data = "id="+value;
			$.post(
				"files/download.do",
				data,
				function(data){
					alert("a");
				},
				"json"
			);
		}
</script>

</head>
<body style="height: 800px" id="mainbody">
	<p style="margin-bottom: 20px"><img src="css/luyan/img/icons/contacts.png" width="32px" height="32px"/>&nbsp;&nbsp;<span>文档管理</span></p>   
	<!-- 整个容器 -->
	<div id="mycontent" style="height:500px">
	    <div class="content">
				<div id="u4" style="margin-left: 0px;width: 700px">
					文件名：<input id="name2"  name="name2" type="text" style="width: 70px" /> 
					
					<input id="btn" type="button" style="width: 50px;height: 20px;font-size: 10px" value="检索" />
				</div>

			</div>
			<table id="dg" cellpadding="0" cellspacing="0">
			</table>
	
	<!-- 修改文件夹-->
			<div id="div3">
				<input type="hidden" name="files.id" id="id1">
				文件名：<input id="name1" name="name1"   type="text"/><br/><br/>
				路径：<span id="path1"></span><br/><br/>
				创建人：<span id="userid1"></span><br/><br/>
				创建时间：<span id="createdate1"></span><br/><br/>
				<input id="folderid10" type="hidden" />
			</div>
	<!-- 新增文件 -->
				<div id="div4">
				创建人：${user.name}<br/><br/>
				创建时间：<span id="sp"></span><br/><br/>
				文件名：<input id="name4" name="name4"   type="text"/><br/><br/>
				路径：/文档管理/${user.deptname}/${folder.name}/<br /><br/><br/>
				<form enctype="multipart/form-data" method="post" action="files/upload.do" id="myform" target="fff">
				文件上传：<input id="fileup" name="file" type="file" />
						<input type="submit" value="上传" />
				</form>
				<iframe id="fff" name="fff" style="display: none;">
				</iframe>
			</div>
	  <input id="folderid" value="${folder.id}" type="hidden"/>
	  <input id="userid4" value="${user.id}" type="hidden"/>
	  <input id="foldername" value="${folder.name}" type="hidden"/>
  </div>	
</body>
</html>
